import request from '/@/utils/request';
import { useUrlUtil } from '/@/utils/urlUtil';
import { BaseRequest, BaseResponse } from '/@/interfaces/BaseModel';
import { TaskInfoApi } from '/@/enums/dpp-api-enum';
import {
    TaskInfoSearchParamModel,
    TaskInfoListModel,
    TaskInfoDetailModel,
    TaskInfoAddParamModel,
    TaskInfoEditParamModel,
    TaskInfoDeleteParamModel
} from '/@/interfaces/DataPipelineModel';

function useTaskInfo() {
    return {
        list: function (payload: BaseRequest<TaskInfoSearchParamModel>) {
            return request.post<BaseResponse<TaskInfoListModel[]>>(TaskInfoApi.LIST, payload);
        },
        detail: function (payload: Object) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<TaskInfoDetailModel>>(useUrl.joinParam(TaskInfoApi.DETAIL, payload));
        },
        add: function (payload: BaseRequest<TaskInfoAddParamModel>) {
            return request.post<BaseResponse<boolean>>(TaskInfoApi.ADD, payload);
        },
        edit: function (payload: BaseRequest<TaskInfoEditParamModel>) {
            return request.post<BaseResponse<boolean>>(TaskInfoApi.EDIT, payload);
        },
        triggerEnable: function (payload: Object) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<TaskInfoDetailModel>>(useUrl.joinParam(TaskInfoApi.TRIGGER_ENABLE, payload));
        },
        del: function (payload: BaseRequest<TaskInfoDeleteParamModel>) {
            return request.post<BaseResponse<boolean>>(TaskInfoApi.DEL, payload);
        },
    };
}

export default useTaskInfo;